<template>
  <div class="info-container">
    <!-- 属性编辑弹窗 -->
    <el-dialog
      v-model="editStatusVisible"
      :title="currentEditType === 'stats' ? '编辑属性' : '编辑亚属性'"
      width="414px"
      style="padding: 0; border-radius: 9px"
      align-center
      :show-close="false"
    >
      <!-- 头部 -->
      <template #header>
        <div class="custom-header">
          <span class="dialog-title">{{ currentEditType === "stats" ? "属性" : "亚属性" }}</span>
          <i class="el-icon-close close-btn" @click="editStatusVisible = false">
            <el-icon><Close /></el-icon>
          </i>
        </div>
      </template>
      <!-- 选择部分 -->
      <div class="select-box">
        <span class="text">{{ currentEditType === "stats" ? "属性" : "亚属性" }}</span>
        <el-select v-model="selectValue" style="width: 240px" placeholder="请选择">
          <el-option
            v-for="item in currentOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>

      <template #footer>
        <div class="dialog-footer">
          <el-button class="cancel-btn" @click="editStatusVisible = false">取消</el-button>
          <el-button class="confirm-btn" type="primary" @click="handleConfirm">确定</el-button>
        </div>
      </template>
    </el-dialog>

    <div class="info-card">
      <div v-for="currentInfo in currentType" :key="currentInfo.key" class="info-row">
        <div class="label">{{ currentInfo.label }}</div>
        <div class="value">
          <!-- 图片显示区域 -->
          <template v-if="['title', 'wealthLevel', 'nameplate'].includes(currentInfo.key)">
            <img
              v-if="infoType[currentInfo.key]"
              :src="infoType[currentInfo.key]"
              class="icon-image"
              alt="icon"
            />
          </template>
          <template v-if="currentInfo.key === 'nameplate'">
            {{ infoType[currentInfo.key] || "" }}
            <span v-if="!infoType[currentInfo.key]" class="edit">编辑</span>
          </template>
          <template v-else>
            {{ infoType[currentInfo.key] }}
            <span
              v-if="currentInfo.key === 'stats' || currentInfo.key === 'subattribute'"
              class="edit"
              @click="openDialog(currentInfo.key)"
            >
              编辑
            </span>
          </template>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
export default {
  name: "CurrentInfo",
};
</script>
<script setup lang="ts">
import { ref, computed } from "vue";

const infoType = ref({
  fansNumber: "254人",
  concernNumber: "15人",
  title: "",
  starLevel: "15级",
  wealthLevel: "",
  nameplate: "",
  area: "四川省广元市",
  stats: "L",
  subattribute: "SADO",
});

const selectValue = ref("");
const currentEditType = ref<"stats" | "subattribute">("stats");

const statsOptions = [
  { value: "L", label: "L" },
  { value: "M", label: "M" },
  { value: "XL", label: "XL" },
];

const subattributeOptions = [
  { value: "无", label: "无" },
  { value: "SADO", label: "SADO" },
  { value: "MASO", label: "MASO" },
  { value: "DOM", label: "DOM" },
  { value: "SUB", label: "SUB" },
  { value: "TFTB", label: "TFTB" },
  { value: "白骑士", label: "白骑士" },
];

const currentType = [
  { label: "粉丝数量:", key: "fansNumber" },
  { label: "关注数量:", key: "concernNumber" },
  { label: "称号:", key: "title" },
  { label: "明星等级:", key: "starLevel" },
  { label: "财富等级:", key: "wealthLevel" },
  { label: "守护铭牌:", key: "nameplate" },
  { label: "所在地区:", key: "area" },
  { label: "属性:", key: "stats" },
  { label: "亚属性:", key: "subattribute" },
];

const currentOptions = computed(() => {
  return currentEditType.value === "stats" ? statsOptions : subattributeOptions;
});

const editStatusVisible = ref(false);

const openDialog = (type: "stats" | "subattribute") => {
  currentEditType.value = type;
  selectValue.value = infoType.value[type];
  editStatusVisible.value = true;
};

const handleConfirm = () => {
  if (currentEditType.value) {
    infoType.value[currentEditType.value] = selectValue.value;
  }
  editStatusVisible.value = false;
};

defineExpose({
  openDialog,
});
</script>

<!-- 样式部分保持不变 -->

<style lang="scss" scoped>
.info-container {
  padding: 15px;
  font-family: Arial, sans-serif;

  //弹窗头部
  .custom-header {
    position: relative;
    display: flex;
    align-items: center;
    padding: 32px;
    border-bottom: 1px solid #e0e0e0;
    .dialog-title {
      font-size: 16px;
      color: rgba(0, 0, 0, 0.9);
    }

    .close-btn {
      position: absolute;
      right: 20px;
      top: 50%;
      transform: translateY(-50%);
      cursor: pointer;
      font-size: 16px;
      color: #999;
      transition: color 0.2s;

      &:hover {
        color: #666;
      }
    }
  }
  .select-box {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 50px;
    .text {
      padding: 8px 0;
      margin-right: 20px;
      white-space: nowrap;
    }
  }
  .dialog-footer {
    border-top: 1px solid #e0e0e0;
    padding: 24px 32px;
    .confirm-btn {
      padding: 8px 29px;
      border-radius: 2px 2px 2px 2px;
      background: #3c80ff;
      box-shadow: 0px 2px 2px 0px rgba(22, 93, 255, 0.6);
      border-radius: 2px 2px 2px 2px;
    }
    .cancel-btn {
      padding: 8px 29px;
      color: #86909c;
      border-radius: 2px 2px 2px 2px;
      background: #f2f3f5;
      border-radius: 2px 2px 2px 2px;
    }
  }
}
.info-card {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px 0;
  width: 100%;
  margin-left: auto;
  .info-row {
    width: 25%;
    display: flex;
    padding: 0 8px;
    box-sizing: border-box;
    font-size: 14px;
    font-weight: 400;
    gap: 20px;

    .label {
      flex-shrink: 0;
      width: 100px;
      text-align: right;
      white-space: nowrap;
      padding: 8px;
      font-weight: 500;
      color: #4e5969;
      // background-color: lightblue;
    }
    .value {
      flex: 1;
      width: 160px;
      white-space: nowrap;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      gap: 2px;
      // background-color: lightgoldenrodyellow;

      .edit {
        color: #1890ff;
        margin-left: 8px;
        cursor: pointer;
        font-size: 12px;
      }
    }
  }
}
//下拉选择器去边框
::v-deep .el-select__wrapper {
  box-shadow: none !important; // 去除默认阴影
  background-color: #f5f5f5 !important;
  border-radius: 0px 0px 0px 0px;
}
</style>
